<?php
namespace app\api\controller;
use app\admin\model\articel\Article as ArticleModel;
use app\admin\model\Articlecategory;
use app\common\controller\Api;
class Article extends Api
{
    protected $noNeedRight = '*';
    protected $noNeedLogin = '*';

    public function _initialize()
    {
        parent::_initialize();
    }
    public function  categories(){

        $categoryModel=  new Articlecategory();

        $categories= $categoryModel->where(['deletetime'=>null])->select();
        $this->success('获取成功',$categories);
    }

    public function list(){
//        $this->request->param('list_rows', 10);
        $where=[
            'is_show'=>1,
            'is_notice'=>0
        ];
        $params =$this->request->param();
        if(isset($params['cate_id']) && $params['cate_id'] > 0){
            $where['cate_id']=$params['cate_id'];
        }
        $list = (new ArticleModel())->where($where)->order("id", "desc")
            ->field('id,cate_id,title,synopsis,image,visit,likes')
            ->paginate($this->request->param('list_rows', 1));;
        $this->success("success", $list);
    }

    public function detail(){
        $id = $this->request->get("id");
        $article= ArticleModel::where("id", $id)->find();
        if($article){
//            visit
            ArticleModel::where("id", $id)->update(['visit'=>$article['visit']+1,'update_time'=>time()]);
        }
        $this->success("success", $article);
    }
    //公司介绍文稿
    public function companyinfo(){
        $id = 1;
        $this->success("success", ArticleModel::where("id", $id)->find());
    }
    //隐私协议
    public function privacy(){
        $id=2;
        $this->success("success", ArticleModel::where("id", $id)->find());
    }
}
